USE [QuanLyHopDong]
GO

/****** Object:  View [dbo].[KhoiLuongHopDongView]    Script Date: 2/13/2015 2:12:49 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO



/****** Object:  View [dbo].[KhoiLuongHopDongView]    Script Date: 8/17/2014 4:38:43 PM ******/

ALTER VIEW [dbo].[KhoiLuongHopDongView]
AS
SELECT      KL.Id, KL.HopDongId, DV.Ten AS TenDonVi, 
			HD.TrangThai, HD.SoHopDong, HD.LoaiDuAn, HD.EmployeeId, HD.TenHopDong,
			KL.MaTuyen, KL.TienDoThiCong, KL.GhiChu, KL.NhanVatTuA, DD.Ma AS DiemDau, DC.Ma AS DiemCuoi, 
			KL.ChieuDaiTuyen, KL.DoiThiCongId,
                         LC.Name AS TenLoaiCap
						 , TTTC.Id as TinhTrangThiCongId, TTTC.Name AS TinhTrangThiCong
						 , TTVT.Id as TinhTrangVatTuId, TTVT.Name AS TinhTrangVatTu,
						 DTC.Ten as TenDoiThiCong
FROM            dbo.KhoiLuongHopDong AS KL LEFT OUTER JOIN
                         dbo.HopDong AS HD ON KL.HopDongId = HD.Id LEFT OUTER JOIN
                         dbo.DonVi AS DV ON HD.DonViId = DV.Id LEFT OUTER JOIN
                         dbo.DiaDiem AS DD ON KL.DiemDauId = DD.Id LEFT OUTER JOIN
                         dbo.DiaDiem AS DC ON KL.DiemCuoiId = DC.Id LEFT OUTER JOIN
                         dbo.LoaiCap AS LC ON KL.LoaiCapId = LC.Id LEFT OUTER JOIN
						 dbo.TinhTrangThiCong AS TTTC on KL.TienDoThiCong = TTTC.Id LEFT OUTER JOIN
						 TinhTrangVatTu AS TTVT on KL.NhanVatTuA = TTVT.Id LEFT OUTER JOIN
						 dbo.DoiThiCong AS DTC on KL.DoiThiCongId = DTC.Id




GO


